package com.api;

import android.util.Log;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.net.SocketTimeoutException;

/* access modifiers changed from: package-private */
public final class c extends Thread {
    final /* synthetic */ LTLink u;
    private boolean v;
    private DatagramSocket w;

    public c(LTLink lTLink) {
        this.u = lTLink;
    }

    public final void d() {
        this.v = false;
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public final void run() {
        byte[] bArr = new byte[1024];
        int i = 0;
        while (this.v) {
            try {
                this.w.receive(new DatagramPacket(bArr, 1024));
            } catch (SocketTimeoutException e) {
                Log.d(LTLink.TAG, "count =" + i);
                if (this.u.r != 1 && (i = i + 1) > 10) {
                    LTLink.c(1000);
                    i = 0;
                }
                synchronized (this.u.o) {
                    this.u.o.notify();
                }
            } catch (IOException e2) {
                e2.printStackTrace();
            }
        }
        if (this.w != null) {
            this.w.close();
            this.w = null;
        }
    }

    @Override // java.lang.Thread
    public final void start() {
        this.v = true;
        Log.d(LTLink.TAG, "RecvThread start");
        if (this.w == null) {
            try {
                this.w = new DatagramSocket(this.u.f);
                this.w.setSoTimeout(this.u.h);
            } catch (SocketException e) {
                e.printStackTrace();
                return;
            }
        }
        super.start();
    }
}
